package com.soc.utils;

import java.util.List;
import java.util.Map.Entry;
import org.nature.framework.core.NatureMap;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Convert {
	
	//权限管理
	public static final String PERM_PERMIT_QUERY = "1004";//查询
	
	//员工管理
	public static final String PERM_EMPLOYEE_ADD = "2001";//增加
	public static final String PERM_EMPLOYEE_DEL = "2002";//删除
	public static final String PERM_EMPLOYEE_UPDATE = "2003";//修改
	public static final String PERM_EMPLOYEE_QUERY = "2004";//查询
	
	public static String getSuffix(String filename, char split) {
		int index = filename.lastIndexOf(split);
		return index >= 0 ? filename.substring(index) : "";
	}

	public static JSONArray natureMapListToJsonArray(List<NatureMap> nms) {
		JSONArray ja = new JSONArray();
		for (NatureMap nm : nms) {
			JSONObject jo = new JSONObject();
			jo = natureMapToJsonObject(nm);
			ja.add(jo);
		}
		return ja;
	}

	public static JSONObject natureMapToJsonObject(NatureMap nm) {
		JSONObject jo = new JSONObject();
		for (Entry<String, Object> entry : nm.entrySet()) {
			jo.put(entry.getKey(), entry.getValue());
		}
		return jo;
	}

	public static NatureMap getPERMs() {
		NatureMap PERMs = new NatureMap();
		PERMs.put("PERM_PERMIT_QUERY", PERM_PERMIT_QUERY);
		
		PERMs.put("PERM_EMPLOYEE_ADD", PERM_EMPLOYEE_ADD);
		PERMs.put("PERM_EMPLOYEE_DEL", PERM_EMPLOYEE_DEL);
		PERMs.put("PERM_EMPLOYEE_UPDATE", PERM_EMPLOYEE_UPDATE);
		PERMs.put("PERM_EMPLOYEE_QUERY", PERM_EMPLOYEE_QUERY);
		return PERMs;
	}
}
